package com.atguigu.guli.service.edu.controller;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Video;
import com.atguigu.guli.service.edu.feign.VodService;
import com.atguigu.guli.service.edu.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2022-01-04
 */
@RestController
@CrossOrigin
@RequestMapping("/edu/video")
public class VideoController {
@Autowired
    private VideoService videoService;
@Autowired
    private VodService vodService;

   @PostMapping("/addVideo")
    public R addVideo(@RequestBody Video video){
       videoService.save(video);
       return R.ok();
   }

   @DeleteMapping("{id}")
    public R deleteVideo(@PathVariable String id){

       Video byId = videoService.getById(id);
       vodService.deleteVideo(byId.getVideoSourceId());
       videoService.removeById(id);
       return R.ok();
   }

}

